#include "gdt.h"
#include "tss.h"

gdt_entry gdt[GDT_COUNT] = {
	/* Descriptor nulo*/
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },

	
	/** CODIGO 4GB **/
	(gdt_entry){ 
		(unsigned short) 0xFFFF,	 //limit 0 15
		(unsigned short) 0x0000, 	 // base 0 15
		(unsigned char) 0x00,   	 // base 23 16
		(unsigned char) 0xA,    	 //type
		(unsigned char) 1, 			 	 //s -> 1=code/data 0=system
		(unsigned char) 0, 			   //dpl -> privilegio
		(unsigned char) 1, 			   //p ->presente
		(unsigned char) 0xF,		   //limit 16 19
		(unsigned char) 0,  		   //avl
		(unsigned char) 0,  		   //l ->64bit
		(unsigned char) 1,  		   //db
		(unsigned char) 1, 		     //g
		(unsigned char) 0x00 		   //base 31 24
	},

	/** DATOS 4GB **/
   	(gdt_entry){ 
		(unsigned short) 0xFFFF,	// limit 0 15
		(unsigned short) 0x0000,	// base 0 15
		(unsigned char) 0x00,		// base 23 16
		(unsigned char) 0x2,		// type
		(unsigned char) 1,			// s -> 1=code/data 0=system
		(unsigned char) 0, 			// dpl -> privilegio
		(unsigned char) 1, 			// p -> presente
		(unsigned char) 0xF,		// limit 16 19
		(unsigned char) 0,  		// avl
		(unsigned char) 0,  		// l -> 64bit
		(unsigned char) 1,  		// db
		(unsigned char) 1, 			// g
		(unsigned char) 0x00 		// base 31 24
	},	

	/** VIDEO **/
    	(gdt_entry){ 
		(unsigned short) 0x0F9F,	// Limit 0-15 = 25*80*2 - 1
		(unsigned short) 0x8000,	// base 0-15
		(unsigned char) 0x0B,		// base 23-16
		(unsigned char) 0x2, 		// type
		(unsigned char) 1, 			// s-> 1=code/data 0=system
		(unsigned char) 0,			// privilegio de kernel
		(unsigned char) 1, 			// presente
		(unsigned char) 0x0,		// limit 16-19
		(unsigned char) 0,  		// avl
		(unsigned char) 0,  		// 
		(unsigned char) 1,  		//
		(unsigned char) 0, 			//g
		(unsigned char) 0x00 		// base 31-24
	},
	
		/** CODIGO 2 4GB **/
	(gdt_entry){ 
		(unsigned short) 0xFFFF,	 //limit 0 15
		(unsigned short) 0x0000, 	 // base 0 15
		(unsigned char) 0x00,   	 // base 23 16
		(unsigned char) 0xA,    	 //type
		(unsigned char) 1, 			 	 //s -> 1=code/data 0=system
		(unsigned char) 3, 			   //dpl -> privilegio
		(unsigned char) 1, 			   //p ->presente
		(unsigned char) 0xF,		   //limit 16 19
		(unsigned char) 0,  		   //avl
		(unsigned char) 0,  		   //l ->64bit
		(unsigned char) 1,  		   //db
		(unsigned char) 1, 		     //g
		(unsigned char) 0x00 		   //base 31 24
	},

	/** DATOS 2 4GB **/
   	(gdt_entry){ 
		(unsigned short) 0xFFFF,	// limit 0 15
		(unsigned short) 0x0000,	// base 0 15
		(unsigned char) 0x00,		// base 23 16
		(unsigned char) 0x2,		// type
		(unsigned char) 1,			// s -> 1=code/data 0=system
		(unsigned char) 3, 			// dpl -> privilegio
		(unsigned char) 1, 			// p -> presente
		(unsigned char) 0xF,		// limit 16 19
		(unsigned char) 0,  		// avl
		(unsigned char) 0,  		// l -> 64bit
		(unsigned char) 1,  		// db
		(unsigned char) 1, 			// g
		(unsigned char) 0x00 		// base 31 24
	},	

};

gdt_descriptor GDT_DESC = {sizeof(gdt)-1, (unsigned int)&gdt};


